/*
 * @Description:
 * @Date: 2024-02-25 20:49:38
 * @LastEditTime: 2024-03-03 14:02:50
 * @FilePath: /pure-admin-thin/src/user.ts
 */
import { http } from "@/utils/http";

export interface ProductInfo {
  id: string;
  name: string;
  desc: string;
  detail: string;
  attribute_list: [];
  images: string[];
  specs: [];
}

export interface ProductResult {
  code: number;
  message: string;
  data: ProductInfo;
}

export interface ProductListResult {
  code: number;
  message: string;
  data: ProductInfo[];
}

/** 获取商品详情 */
export const getProduct = (id: string) => {
  return http.request<ProductResult>("get", `/store/products/${id}`, {});
};

export const getProductList = () => {
  return http.request<ProductListResult>("get", `/store/products`, {});
};

/** 刷新token */
export const addProduct = (data?: object) => {
  return http.request<ProductResult>("post", "/store/products", { data });
};

export const handle_all_files = (data?: object) => {
  return http.request<ProductResult>("post", "/list_all_file", { data });
};

export const updateProduct = (id: string, data?: object) => {
  return http.request<ProductResult>("put", "/store/products/" + id, {
    data
  });
};

export const delProduct = (id: string, data?: object) => {
  return http.request<ProductResult>("delete", "/store/products/" + id, {
    data
  });
};

export const refreshTokenApi = (data?: object) => {
  return http.request<ProductResult>("post", "/refreshToken", { data });
};

export const callSession = (data?: object) => {
  return http.request<ProductResult>(
    "post",
    "/call-session",
    { data },
    {
      responseType: "stream" // 重要：将响应类型设置为流
    }
  );
};
